from .base_champion import Champion
from typing import Dict, List, Optional


class HealingMonk(Champion):
    def __init__(self):
        super().__init__(
            name="Healing Monk",
            health=120,
            attack=15,
            defense=12,
            speed=18,
            mana=160
        )
    
    def get_abilities(self) -> List[str]:
        return ["Heal", "Group Heal", "Blessing", "Divine Protection"]
    
    def use_ability(self, ability_name: str, target: Optional[Champion] = None) -> Dict:
        if not self._is_alive:
            return {"success": False, "message": "Cannot use ability - champion is dead"}
        
        if self._is_silenced:
            return {"success": False, "message": f"{self.name} is silenced and cannot use abilities"}
        
        if ability_name == "Heal":
            return self._heal(target)
        elif ability_name == "Group Heal":
            return self._group_heal()
        elif ability_name == "Blessing":
            return self._blessing(target)
        elif ability_name == "Divine Protection":
            return self._divine_protection()
        else:
            return {"success": False, "message": f"Unknown ability: {ability_name}"}
    
    def _heal(self, target: Optional[Champion]) -> Dict:
        if not target or not target.is_alive:
            return {"success": False, "message": "No valid target"}
        
        if not self.consume_mana(20):
            return {"success": False, "message": "Not enough mana"}
        
        heal_amount = 50
        actual_healing = target.heal(heal_amount)
        
        return {
            "success": True,
            "healing": actual_healing,
            "message": f"{self.name} heals {target.name} for {actual_healing} health!"
        }
    
    def _group_heal(self) -> Dict:
        if not self.consume_mana(40):
            return {"success": False, "message": "Not enough mana"}
        
        return {
            "success": True,
            "message": f"{self.name} performs Group Heal! (Heals all allies)"
        }
    
    def _blessing(self, target: Optional[Champion]) -> Dict:
        if not target or not target.is_alive:
            return {"success": False, "message": "No valid target"}
        
        if not self.consume_mana(25):
            return {"success": False, "message": "Not enough mana"}
        
        target._buffs.append({
            "type": "blessing",
            "attack_boost": 8,
            "defense_boost": 5,
            "speed_boost": 3,
            "duration": 4
        })
        
        return {
            "success": True,
            "message": f"{self.name} blesses {target.name} with divine power! (+8 attack, +5 defense, +3 speed for 4 turns)"
        }
    
    def _divine_protection(self) -> Dict:
        if not self.consume_mana(50):
            return {"success": False, "message": "Not enough mana"}
        
        return {
            "success": True,
            "message": f"{self.name} calls upon Divine Protection! (All allies gain damage reduction)"
        }
    
    def get_champion_type(self) -> str:
        return "Support"


class ShieldBearer(Champion):
    def __init__(self):
        super().__init__(
            name="Shield Bearer",
            health=160,
            attack=20,
            defense=30,
            speed=12,
            mana=100
        )
    
    def get_abilities(self) -> List[str]:
        return ["Shield Wall", "Protect Ally", "Fortify", "Guardian's Call"]
    
    def use_ability(self, ability_name: str, target: Optional[Champion] = None) -> Dict:
        if not self._is_alive:
            return {"success": False, "message": "Cannot use ability - champion is dead"}
        
        if self._is_silenced:
            return {"success": False, "message": f"{self.name} is silenced and cannot use abilities"}
        
        if ability_name == "Shield Wall":
            return self._shield_wall()
        elif ability_name == "Protect Ally":
            return self._protect_ally(target)
        elif ability_name == "Fortify":
            return self._fortify()
        elif ability_name == "Guardian's Call":
            return self._guardians_call()
        else:
            return {"success": False, "message": f"Unknown ability: {ability_name}"}
    
    def _shield_wall(self) -> Dict:
        if not self.consume_mana(30):
            return {"success": False, "message": "Not enough mana"}
        
        self._buffs.append({
            "type": "shield_wall",
            "defense_boost": 20,
            "damage_reduction": 40,
            "duration": 4
        })
        
        return {
            "success": True,
            "message": f"{self.name} creates a Shield Wall! +20 defense, 40% damage reduction for 4 turns!"
        }
    
    def _protect_ally(self, target: Optional[Champion]) -> Dict:
        if not target or not target.is_alive:
            return {"success": False, "message": "No valid target"}
        
        if not self.consume_mana(25):
            return {"success": False, "message": "Not enough mana"}
        
        target._buffs.append({
            "type": "protection",
            "damage_reduction": 50,
            "duration": 3
        })
        
        return {
            "success": True,
            "message": f"{self.name} protects {target.name} from harm! (50% damage reduction for 3 turns)"
        }
    
    def _fortify(self) -> Dict:
        if not self.consume_mana(35):
            return {"success": False, "message": "Not enough mana"}
        
        return {
            "success": True,
            "message": f"{self.name} fortifies all allies! (All allies gain defense boost)"
        }
    
    def _guardians_call(self) -> Dict:
        if not self.consume_mana(45):
            return {"success": False, "message": "Not enough mana"}
        
        self._buffs.append({
            "type": "guardian_spirits",
            "attack_boost": 10,
            "defense_boost": 15,
            "healing_per_turn": 10,
            "duration": 5
        })
        
        return {
            "success": True,
            "message": f"{self.name} calls upon Guardian Spirits! +10 attack, +15 defense, +10 healing per turn for 5 turns!"
        }
    
    def get_champion_type(self) -> str:
        return "Support"

